package cn.zch.soft.util.task.gitee.repo.info;
import cn.zch.soft.util.http.okhttpclient.OkHttpClientUtil;
import cn.zch.soft.util.task.gitee.repo.common.CommonHeader;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
 * gitee仓库大小分析 太麻烦 没有完全解析出来还 不再使用 转用 gitee-api-java-client
 * https://gitee.com/profile/repo_info?page=2
 *
 * @author zchcpywin10
 */
@Slf4j
public class TaskGiteeRepSize {
  public static void main(String[] args) {
    getGiteeRepInfo();
  }
  public static void getGiteeRepInfo() {
    // String url = "https://gitee.com/profile/repo_info_chart?page="
    String baseUrl = "https://gitee.com/profile/repo_info?page=";
    String fullUrl;
    for (int i = 1; i <= 1; i++) {
      fullUrl = baseUrl + i;
      System.out.println("i = " + i);
      try {
        String bodyStr = OkHttpClientUtil.doRequest(fullUrl, "GET", null, CommonHeader.commonHeaders());
        System.out.println("bodyStr = " + bodyStr);
        if (null != bodyStr) {
          // println(i + " result = " + bodyStr)
          String bodyReplace1 = bodyStr
            //
            .replace("\\n", "")
            //
            .replace("\\", "")
            //
            .replace("$('.profile-repo-info-page .container-table').find('tbody').html('", "")
            //
            .replace("\");","")
            //
            ;
          int i1 = bodyReplace1.indexOf("$('.profile-repo-info-page .timeago').timeago()");
          System.out.println("i1 = " + i1);
          String[] bodyReplace1Split = bodyReplace1.split("$('.profile-repo-info-page .timeago').timeago()");
          System.out.println();
          System.out.println();
          System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
          for (String s : bodyReplace1Split) {
            System.out.println(s);
          }
          System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
          System.out.println();
          System.out.println();
          // 6. Jsoup 解析 html
          Document document = Jsoup.parse(bodyReplace1);
          System.out.println();
          System.out.println();
          System.out.println();
          System.out.println("document = " + document);
          System.out.println();
          System.out.println();
          System.out.println();
          System.out.println("***************************************************");
          System.out.println("***************************************************");
          Elements table = document.getElementsByTag("table");
          for (Element element : table) {
            System.out.println("||||:" + element);
          }
        }
        else {
          break;
        }
      }
      catch (Exception e) {
        log.error(e.getLocalizedMessage());
      }
    }
  }
}
